home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.5)
-
- from __future__ import with_statement
- from __future__ import division
- import wx
- from util import traceguard, urlcacheopen
- from util.httplib2 import cached_content
- from cStringIO import StringIO
- from traceback import print_exc
- from gui import skin
- from gui.buddylist.renderers import get_buddy_icon
- from common import profile
- from common import pref
- import logging
- log = logging.getLogger('gui.htmlbitmaps')
- import PIL
- from wx import EVT_ERASE_BACKGROUND, EVT_PAINT, EVT_LEFT_UP, EVT_MOTION, RectS, ImageFromString, Panel, BitmapFromImage, AutoBufferedPaintDC, WHITE_BRUSH, TRANSPARENT_PEN, StockCursor, CURSOR_HAND, CURSOR_DEFAULT, Bitmap, BG_STYLE_CUSTOM, ImageFromBitmap, EmptyImage, GetApp, Size
- from wx.html import HtmlLinkInfo, HtmlLinkEvent
- HTML_ELEM_POS = (-1000, -1000)
-
- class BitmapFromData(Panel):
-
- def __init__(self, parent, size = (-1, -1), padding = (0, 0), data = None, href = None):
- self.href = href
- traceguard.__enter__()
-
- try:
- self.data = data.decode('base64')
- self.image = ImageFromString(self.data)
- self.tofinger = True
- Panel.__init__(self, parent, size = size + padding, pos = HTML_ELEM_POS)
- self.SetBackgroundStyle(BG_STYLE_CUSTOM)
- self.bitmap = BitmapFromImage(self.image.Rescale(*size))
- if not self.bitmap.IsOk():
- self.bitmap = wx.EmptyBitmap(*size)
-
- self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
- Bind = self.Bind
- Bind(EVT_PAINT, self.OnPaint)
- Bind(EVT_LEFT_UP, self.OnLeftUp)
- Bind(EVT_MOTION, self.OnMouseMotion)
- finally:
- pass
-
-
-
- def OnPaint(self, event):
- traceguard.__enter__()
-
- try:
- dc = AutoBufferedPaintDC(self)
- rect = RectS(self.Size)
- dc.SetBrush(WHITE_BRUSH)
- dc.SetPen(TRANSPARENT_PEN)
- dc.DrawRectangleRect(rect)
- dc.DrawBitmap(self.bitmap, 0, 0, True)
- finally:
- pass
-
-
-
- def OnMouseMotion(self, event):
- inside = RectS(self.bitmap.Size).Contains(event.Position)
- if inside and self.tofinger:
- self.tofinger = False
- self.SetCursor(StockCursor(CURSOR_HAND))
- elif not inside and not (self.tofinger):
- self.tofinger = True
- self.SetCursor(StockCursor(CURSOR_DEFAULT))
-
-
-
- def OnLeftUp(self, event):
- traceguard.__enter__()
-
- try:
- if self.href is None:
- return None
-
- if RectS(self.bitmap.Size).Contains(event.Position):
- linkinfo = HtmlLinkInfo(self.href)
- evt = HtmlLinkEvent(-1, linkinfo)
- self.Parent.AddPendingEvent(evt)
- self.Top.Hide()
- finally:
- pass
-
-
-
-
- class BitmapFromSkin(Panel):
-
- def __init__(self, parent, key, size = (-1, -1), padding = (0, 0)):
- traceguard.__enter__()
-
- try:
- Panel.__init__(self, parent, pos = HTML_ELEM_POS)
- incoming = skin.get(key)
- self.bitmap = traceguard if isinstance(incoming, Bitmap) else incoming.GetBitmap(size)
- if not self.bitmap.IsOk():
- self.bitmap = wx.EmptyBitmap(*size)
-
- self.Size = wx.Size(self.bitmap.Size.width, self.bitmap.Size.height + padding[0] + padding[1])
- self.padding = padding
- self.Bind(EVT_PAINT, self.OnPaint)
- self.SetBackgroundStyle(BG_STYLE_CUSTOM)
- finally:
- pass
-
-
-
- def OnPaint(self, event):
- traceguard.__enter__()
-
- try:
- dc = AutoBufferedPaintDC(self)
- rect = RectS(self.Size)
- dc.Brush = WHITE_BRUSH
- dc.Pen = TRANSPARENT_PEN
- dc.DrawRectangleRect(rect)
- dc.DrawBitmap(self.bitmap, 0, self.padding[0], True)
- finally:
- pass
-
-
-
-
- class BuddyIcon(Panel):
-
- def __init__(self, parent, contid, size = None):
- traceguard.__enter__()
-
- try:
- (proto, acct, buddy) = contid.split('/', 2)
- contact = GetApp().StupidContactHack
- icosize = pref('infobox.iconsize', 64)
- self.bitmap = get_buddy_icon(contact, icosize, round_size = 0, grey_offline = False)
- if not self.bitmap.IsOk():
- self.bitmap = wx.EmptyBitmap(*icosize)
-
- Panel.__init__(self, parent, size = (icosize, icosize), pos = HTML_ELEM_POS)
- self.SetBackgroundStyle(BG_STYLE_CUSTOM)
- self.statico = skin.get('statusicons.' + contact.status_orb).ResizedSmaller(16)
- self.Bind(EVT_PAINT, self.OnPaint)
- self.Bind(EVT_ERASE_BACKGROUND, (lambda e: pass))
- self.SetBackgroundStyle(BG_STYLE_CUSTOM)
- finally:
- pass
-
-
-
- def OnPaint(self, event):
- traceguard.__enter__()
-
- try:
- dc = AutoBufferedPaintDC(self)
- rect = RectS(self.Size)
- statico = self.statico
- dc.SetPen(TRANSPARENT_PEN)
- dc.SetBrush(WHITE_BRUSH)
- dc.DrawRectangleRect(rect)
- dc.DrawBitmap(self.bitmap, 0, 0, True)
- dc.DrawBitmap(statico, (rect.width - 16) + (16 - statico.Size.width) // 2, 0, True)
- finally:
- pass
-
-
-
-
- class BitmapFromWeb(Panel):
-
- def __init__(self, parent, url, size = None, href = None, padding = 8, keep_aspect = False, use_image_size = False):
- traceguard.__enter__()
-
- try:
- self.url = url
- self.href = href
- self.padding = padding
- self.tofinger = True
- if url.startswith('skin://'):
- skinpath = url[len('skin://'):]
- bitmap = skin.get(skinpath)
- if use_image_size:
- size = bitmap.Size
-
- if keep_aspect:
- size = _fix_size(size, bitmap.Size)
-
- bitmap = bitmap.Resized(size)
- else:
-
- try:
- image = self._get_pil_url(self.url)
- except Exception:
- traceguard
- traceguard
- bitmap = None
- if size is None:
- size = (45, 0)
-
- except:
- size is None
-
- if use_image_size:
- size = image.size
-
- if keep_aspect:
- size = _fix_size(size, image.size)
-
- bitmap = image.Resized(size).WXB
- if bitmap is None or not bitmap.IsOk():
- self.bitmap = wx.EmptyBitmap(*size)
- else:
- self.bitmap = bitmap
- Panel.__init__(self, parent, size = size + (padding, padding), pos = HTML_ELEM_POS)
- self._init_events()
- finally:
- pass
-
-
-
- def _get_pil_url(self, url):
-
- try:
- f = _[2]
- img = PIL.Image.open(f)
- img.load()
- return img
- finally:
- pass
-
-
-
- def _init_events(self):
- self.SetBackgroundStyle(BG_STYLE_CUSTOM)
- Bind = self.Bind
- Bind(EVT_PAINT, self.OnPaint)
- Bind(EVT_ERASE_BACKGROUND, (lambda e: pass))
- Bind(EVT_LEFT_UP, self.OnLeftUp)
- Bind(EVT_MOTION, self.OnMouseMotion)
-
-
- def OnPaint(self, event):
- dc = AutoBufferedPaintDC(self)
- rect = RectS(self.Size)
- dc.SetBrush(WHITE_BRUSH)
- dc.SetPen(TRANSPARENT_PEN)
- dc.DrawRectangleRect(rect)
- dc.DrawBitmap(self.bitmap, 0, 0, True)
-
-
- def OnMouseMotion(self, event):
- if not self.href:
- return None
-
- inside = RectS(self.bitmap.Size).Contains(event.Position)
- if inside and self.tofinger:
- self.tofinger = False
- self.SetCursor(StockCursor(CURSOR_HAND))
- elif not inside and not (self.tofinger):
- self.tofinger = True
- self.SetCursor(StockCursor(CURSOR_DEFAULT))
-
-
-
- def OnLeftUp(self, event):
- if not self.href:
- return None
-
- if RectS(self.bitmap.Size).Contains(event.Position):
- linkinfo = HtmlLinkInfo(self.href)
- evt = HtmlLinkEvent(-1, linkinfo)
- self.Parent.AddPendingEvent(evt)
- self.Top.Hide()
-
-
-
-
- class BitmapFromWebx2(BitmapFromWeb):
-
- def __init__(self, parent, url1, url2, size = None, href = None, padding = 8, keep_aspect = False, size1 = None, size2 = None, pos1 = (0, 0), pos2 = (3, 3)):
- traceguard.__enter__()
-
- try:
- self.url1 = url1
- self.url2 = url2
- self.href = href
- self.padding = padding
- self.tofinger = True
- self.pos1 = pos1
- self.pos2 = pos2
-
- try:
- image1 = self._get_pil_url(self.url1)
- image2 = self._get_pil_url(self.url2)
- except Exception:
- traceguard
- traceguard
- bitmap1 = None
- bitmap2 = None
- if size is None:
- size = (45, 0)
-
- except:
- size is None
-
- if keep_aspect:
- size1 = _fix_size(size1, image1.GetSize())
- size2 = _fix_size(size2, image1.GetSize())
-
- bitmap1 = image1.Resized(size1).WXB
- bitmap2 = image2.Resized(size2).WXB
- if bitmap1 is None or not bitmap1.IsOk():
- self.bitmap1 = wx.EmptyBitmap(*size1)
- else:
- self.bitmap1 = bitmap1
- if bitmap2 is None or not bitmap2.IsOk():
- self.bitmap2 = wx.EmptyBitmap(*size2)
- else:
- self.bitmap2 = bitmap2
- Panel.__init__(self, parent, size = size + (padding, padding), pos = HTML_ELEM_POS)
- self._init_events()
- finally:
- pass
-
-
-
- def OnPaint(self, event):
- dc = AutoBufferedPaintDC(self)
- rect = RectS(self.Size)
- dc.SetBrush(WHITE_BRUSH)
- dc.SetPen(TRANSPARENT_PEN)
- dc.DrawRectangleRect(rect)
- dc.DrawBitmap(self.bitmap1, self.pos1[0], self.pos1[1], True)
- dc.DrawBitmap(self.bitmap2, self.pos2[0], self.pos2[1], True)
-
-
-
- def _fix_size(target, current, scaleto = 1):
- (wt, ht) = target
- (wc, hc) = current
- ratio = wc / hc
- ratio = ratio * scaleto
- if wt:
- ht = ratio ** -1 * wt
- elif ht:
- wt = ratio * ht
-
- return Size(wt, ht)
-
-